from pydantic import BaseModel


class DspTelemetry(BaseModel):
    cap_out_v: float = 0

    fpga_1v8: float = 0
    fpga_3v3: float = 0

    h3_vdd_3v3: float = 0

    temperature_40mhz: float = 0
    temperature_ad9364: float = 0
    temperature_link_ad9361: float = 0
    temperature_fpga: float = 0
    temperature_h3: float = 0
    temperature_sv1_ad9361: float = 0
    temperature_sv2_ad9361: float = 0

    vbat_mpcie: float = 0

    vdc1_1v3_synth: float = 0
    vdc1_1v3_xcvr: float = 0
    vdc1_1v8: float = 0

    vdc2_1v3_synth: float = 0
    vdc2_1v3_xcvr: float = 0
    vdc2_1v8: float = 0

    vdc3_1v3_synth: float = 0
    vdc3_1v3_xcvr: float = 0
    vdc3_1v8: float = 0

    vdc4_1v3_synth: float = 0
    vdc4_1v3_xcvr: float = 0
    vdc4_1v8: float = 0

    raw_message: str = ''

    def get(self, name: str) -> float:
        return getattr(self, name)

    def set(self, name: str, value: float):
        return setattr(self, name, value)


class DspTelemetryUartInfo(BaseModel):
    class Info(BaseModel):
        index: int
        coefficient: float

    cap_out_v: Info = Info(index=0, coefficient=2.0)

    fpga_1v8: Info = Info(index=1, coefficient=6.6)
    fpga_3v3: Info = Info(index=2, coefficient=2.0)

    h3_vdd_3v3: Info = Info(index=3, coefficient=2.0)

    temperature_40mhz: Info = Info(index=4, coefficient=1.27)
    temperature_ad9364: Info = Info(index=5, coefficient=1.27)
    temperature_link_ad9361: Info = Info(index=6, coefficient=1.27)
    temperature_fpga: Info = Info(index=7, coefficient=1.27)
    temperature_h3: Info = Info(index=8, coefficient=1.27)
    temperature_sv1_ad9361: Info = Info(index=9, coefficient=1.27)
    temperature_sv2_ad9361: Info = Info(index=10, coefficient=1.27)

    vbat_mpcie: Info = Info(index=11, coefficient=2.0)

    vdc1_1v3_synth: Info = Info(index=12, coefficient=2.0)
    vdc1_1v3_xcvr: Info = Info(index=13, coefficient=2.0)
    vdc1_1v8: Info = Info(index=14, coefficient=6.6)

    vdc2_1v3_synth: Info = Info(index=15, coefficient=2.0)
    vdc2_1v3_xcvr: Info = Info(index=16, coefficient=2.0)
    vdc2_1v8: Info = Info(index=17, coefficient=2.0)

    vdc3_1v3_synth: Info = Info(index=18, coefficient=2.0)
    vdc3_1v3_xcvr: Info = Info(index=19, coefficient=2.0)
    vdc3_1v8: Info = Info(index=20, coefficient=2.0)

    vdc4_1v3_synth: Info = Info(index=21, coefficient=2.0)
    vdc4_1v3_xcvr: Info = Info(index=22, coefficient=2.0)
    vdc4_1v8: Info = Info(index=23, coefficient=2.0)

    def get(self, name: str) -> Info:
        return getattr(self, name)
